﻿@{
    ViewBag.Title = "SysLog";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
@model SysLogModel
<ul class="breadcrumb" style="margin-bottom: 7px;">
    <li><a href="#">首页</a> <span class="divider">/</span></li>
    <li><a href="#">系统管理</a> <span class="divider">/</span></li>
    <li class="active">系统日志</li>
</ul>
<form id="searchForm">
    <table style="margin-bottom: 5px">
        <tr>
            <td>日志类型：</td>
            <td>@Html.TextBoxFor(x => x.LogType, new { @class = "input-normal" })</td>
            <td>记录时间：</td>
            <td>@Html.TextBoxFor(x => x.StartTime, new { @class = "calendar" })-@Html.TextBoxFor(x => x.EndTime, new { @class = "calendar" })</td>
            <td>关键字：</td>
            <td>@Html.TextBoxFor(x => x.Keyword, new { @class = "input-normal" })</td>
            <td>用户：</td>
            <td>@Html.TextBoxFor(x => x.Sender, new { @class = "input-normal" })</td>
            <td>
                <button class="button button-small" id="btnSearch" style="margin-left: 5px" type="submit">搜索</button></td>
        </tr>
    </table>
</form>
<div id="grid">
</div>
<script type="text/javascript">
    var Grid = BUI.Grid,
    Store = BUI.Data.Store,
    columns = [
      { title: '类型', sortable: false, dataIndex: 'LogType' },
      { title: '日志描述', sortable: false, dataIndex: 'Msg' },
      { title: 'IP', sortable: false, dataIndex: 'IP' },
      { title: '记录时间', sortable: false, dataIndex: 'CreateTime' },
      { title: '用户', sortable: false, dataIndex: 'CurrentUser' },
      {
          title: '操作', sortable: false, dataIndex: 'ID',
          renderer: function (value, obj) {
              return '<span class="grid-command" onclick="DeletePage(\'' + value + '\')" >删除</span>';
          }
      }
    ];
    //加载列表
    var store = new Store({
        url: '/Admin/System/AjaxGetSysLog',
        proxy: {
            limitParam: 'pageSize',
            method: 'post'
        },
        autoLoad: true,
        pageSize: 10
    }),
    grid = new Grid.Grid({
        render: '#grid',
        loadMask: true,
        forceFit: true,
        plugins: [Grid.Plugins.AutoFit, Grid.Plugins.CheckSelection],
        columns: columns,
        store: store,
        bbar: {
            items: [{
                id: 'delAllBtn',
                elStyle: { 'margin-top': '3px' },
                btnCls: 'button button-small',
                text: '批量清除'
            }],
            pagingBar: true
        }
    });
    grid.render();
    //搜索
    var form = $('#searchForm')[0];
    $(form).on('submit', function (ev) {
        ev.preventDefault();
        var obj = BUI.FormHelper.serializeToObject(form);
        obj.pageIndex = 0;
        obj.start = 0;
        store.load(obj);
    });
    //日期控件
    BUI.use('bui/calendar', function (Calendar) {
        var datepicker = new Calendar.DatePicker({
            trigger: '.calendar',
            maxDate: '2014-01-01',
            minDate: '2013-7-25',
            autoRender: true
        });
    });
    function DeletePage(id) {
        if (confirm('确定删除？')) {
            $.ajax({
                type: 'post',
                data: { ids: id },
                url: '/Admin/System/DeleteLog',
                success: function () {
                    var obj = {};
                    obj.pageIndex = 0;
                    obj.start = 0;
                    store.load(obj);
                }
            })
        }
    }
    $('#delAllBtn').click(function () {
        var selected = grid.getSelection();
        if (selected.length == 0)
            return false;
        var dateArray = [];
        for (var i = 0; i < selected.length; i++) {
            dateArray.push(selected[i].ID);
        }
        DeletePage(dateArray);
    })
</script>

